package cn.iotab.iotkit.transport.api.common.queue;

import cn.iotab.iotkit.queue.queue.QueueMsg;
import cn.iotab.iotkit.queue.queue.QueueProducer;

import java.util.concurrent.ExecutorService;

public class TransportQueueCallback implements QueueProducer.QueueCallback {
    private final SendResultCallback<Void> callback;
    private final ExecutorService executorService;

    public TransportQueueCallback(SendResultCallback<Void> callback,
                                   ExecutorService executorService) {
        this.callback = callback;
        this.executorService = executorService;
    }

    @Override
    public void onSuccess(QueueMsg.Metadata metadata) {
        executorService.submit(() -> callback.onSuccess(null));
    }

    @Override
    public void onFailure(Throwable t) {
        executorService.submit(() -> callback.onError(t));
    }
}
